# node 构建
FROM node:16.13.0 as build-stage
WORKDIR /app
COPY . ./
# 设置 node 阿里镜像
RUN npm config set registry https://registry.npm.taobao.org
# 设置--max-old-space-size
ENV NODE_OPTIONS=--max-old-space-size=16384
# 设置阿里镜像、pnpm、依赖、编译
RUN rm -rf ./node_modules/
# RUN yarn config set registry https://registry.npm.taobao.org -g
# RUN yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g
# RUN yarn add node-sass
# RUN yarn install
# RUN yarn run build

RUN npm install -g cnpm
RUN npm install -g vite
RUN cnpm install unplugin-auto-import@v0.7.1
RUN cnpm install
# RUN cnpm run build
RUN vite build
# node部分结束
RUN echo "🎉 编 🎉 译 🎉 成 🎉 功 🎉"

# nginx 部署
FROM nginx:1.23.3-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html/dist
COPY --from=build-stage /app/nginx.conf /etc/nginx/nginx.conf
EXPOSE 2929
CMD nginx -g 'daemon off;'
RUN echo "🎉 架 🎉 设 🎉 成 🎉 功 🎉"
